﻿@using Website.CRUDServices
@using Website.Models.Styling
@using Location = Website.Models.Domain.Location
@model Website.Models.ViewModels.ListView<Activity>
@{
    this.ViewBag.Title = "Forretningsudvikling";
    this.Layout = "~/Views/_Shared/_Layout.cshtml";
    var allTopics = this.ViewData["DiscussionTopics"] as List<Topic>;
    var allProfiles = this.ViewData["Profiles"] as List<Profile>;
    var allProjects = this.ViewData["Projects"] as List<Project>;
}

<div class="float-right smallMarginBottom">
    <input type="button" onclick="@string.Format("location.href = '{0}';", this.Url.Action("NewBusinessDevelopment"))" value="Opret ny" class="" />
</div>

<table class="tableView">
    <tr>
        @foreach (TableViewHeaderItem item in this.Model.Header.Items)
        {
            <td>
                @Html.Partial("~/Views/_Shared/TableViewHeader.cshtml", item)
            </td>
        }
        <td></td><td></td>
    </tr>
    @if (this.Model != null)
    {
        foreach (Activity act in this.Model.List)
        {
            <tr>
                <td>@string.Format("{0:dd-MM-yyyy}", act.TimeOfActivity)</td>
                <td style="font-size: 0.7em;">
                    @if (act.BDA.Topics.Any())
                    {
                        foreach(var topic in allTopics.Where(x => act.BDA.Topics.Contains(x.ID)).Select(x => x.Title))
                        {
                            @topic
                            <br />
                        }
                    }
                </td>
                <td>
                    @if (act.Commentary.Length < 30)
                    {
                        @act.Commentary
                    }
                    else
                    {
                        @(string.Format("{0}...", act.Commentary.Substring(0, 30)))
                    }

                </td>
                <td style="font-size: 0.7em;">
                    @if (act.Attendees != null && act.Attendees.Any() )
                    {
                        var test1 = allProfiles.Where(x => act.Attendees.Contains(x.ID));
                        foreach(var att in allProfiles.Where(x => act.Attendees.Contains(x.ID)).OrderBy(x => x.Name).Select(x => x.Name))
                        {
                            @att
                            <br />
                        }
                    }
                </td>
                <td style="font-size: 0.7em;">
                    @if(act.OwnerProjects != null && act.OwnerProjects.Any())
                    {
                        foreach (var proj in allProjects.Where(x => act.OwnerProjects.Contains(x.ID)).OrderBy(x => x.Name).Select(x => x.Name))
                        {
                            @proj
                            <br />
                        }
                    }
                </td>
                <td><a href="@Url.Action("UpdateBusinessDevelopment", new { @Id = act.ID })">
                        <img src="@Url.Content("~/Content/ButtonIcons/tool_blue.png")" alt="Link"/></a></td>
                <td><a href="@Url.Action("ViewBusinessDevelopment", new { @Id = act.ID })">
                        <img src="@Url.Content("~/Content/ButtonIcons/notepad_blue.png")" alt="Link"/></a></td>
            </tr>
        }
    }


    <tr>
        @Html.Partial("~/Views/_Shared/PagingArrows.cshtml", 
            Website.Models.Styling.PagingArrows.GetPagingArrowsFromHeader("Index", 2, this.Model)
        )
    </tr>
</table>